package com.admin.controller;

import com.admin.commen.BaseController;
import com.admin.service.RoleService;

import com.fegin.bean.admin.AdminRole;
import com.fegin.bean.common.layuiBean.ResultPage;
import com.fegin.bean.common.layuiBean.VoPage;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author 张子艺
 * @packge com.currency.admin.controller
 * @data 2019-01-16 09:28
 * @project currencycloud
 */
@Controller
@RequestMapping("/admin/role")
public class RoleController extends BaseController {
    @Autowired
    RoleService roleService;

    /**
     * 角色表格查询
     *
     * @param voPage
     * @return
     */
    @RequestMapping(value = "/findRoleByPage")
    @ResponseBody
    public ResultPage<AdminRole> findRoleByPage(@RequestBody VoPage voPage,@RequestParam("flag") int flag,@RequestParam("loginId")Long loginId) {
        return roleService.findRoleByPage(voPage,flag,loginId);
    }

    /**
     * 角色添加
     *
     * @return
     */
    @RequestMapping(value = "/insertRole")
    @ResponseBody
    public Map<String, Object> insertRole(@RequestParam("roleName") String roleName, @RequestParam("menuId") String menuId ,@RequestParam("userId") Long userId ) {
        return roleService.insertRole(roleName, menuId,userId );
    }

    /**
     * 角色添加
     *
     * @return
     */
    @RequestMapping(value = "/insertDistribution")
    @ResponseBody
    public Map<String, Object> insertDistribution(@RequestParam("roleName") String roleName, @RequestParam("menuId") String menuId , @RequestParam("userId")  Long userId) {
        return roleService.insertDistribution(roleName, menuId ,  userId);
    }

    /**
     * 角色所有查询
     *

     * @return
     */
    @RequestMapping(value = "/findRoleAll", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> findRoleAll(@RequestParam("loginId")Long loginId,@RequestParam("flag")int flag) {
        return roleService.findRoleAll( loginId,flag);
    }


    /**
     * 删除角色  AJAX
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/delRole", method = RequestMethod.POST)
    @ResponseBody
    @RequiresPermissions("button:角色管理删除")
    public Map<String, Object> delRole(Long roleId) {
        return roleService.delRole(roleId);
    }


}
